<?php
/** [网站设置控制器]
 * @Author: 976123967@qq.com
 * @Date:   2015-01-09 16:59:21
 * @Last Modified by:   Administrator
 * @Last Modified time: 2015-01-09 18:09:55
 */
class ConfigAction extends PublicAction
{
	public $logic;
	public function _initialize()
	{
		parent::_initialize();
		$this->logic = D('Config','Logic');
		
	}
	
	/**
	 * [index 配置列表]
	 * @return [type] [description]
	 */
	public function index()
	{

		if(IS_POST)
		{
			// 保存信息到数据库
			if(!$this->logic->save_config()) $this->error($this->logic->getError());
			// 将配置信息写入到文件
			if(!$this->logic->write_config())
				$this->error('配置文件写入失败，请检查对应目录的权限',U('Config/index'));
			// 提示
			$this->success('系统设置更新成功',U('Config/index'));
			die;
		}

		$data = $this->logic->get_form();
		$this->assign('data',$data);
		$this->display();
	}

	/**
	 * [update_cache 更新缓存]
	 * @return [type] [description]
	 */
	public function update_cache()
	{
		if(!$this->logic->write_config())
			$this->error("请检查Data文件目录权限");
		$this->success('缓存更新成功');
	}


	/**
	 * [add 添加配置]
	 */
	public function add()
	{
		if(IS_POST)
		{

			if(!$this->logic->add_config())
				$this->error($this->logic->getError());
			$this->success('添加成功',U('Config/index'));
			die;

		}
		$this->display();
	}
	
}